<?php
require_once("./include/appmain.php");
if(sugm_is_logged()){
	sugm_js_goback();
}
if($_POST['action']=='login'){
	$fail = false;
	if(strlen($_POST['login_user'])<1){
		$errorfields['login_name'] = true;
		$errors['login_name_empty'] = true;
		$fail = true;
	}
	if(strlen($_POST['login_password'])<1){
		$errorfields['login_password'] = true;
		$errors['login_password_empty'] = true;
		$fail = true;
	}
	
	
	if(!$fail){
		$return = sugm_user_auth($_POST['login_user'],$_POST['login_password']);
		if($return == true){
			sugm_user_login($_POST['login_user']);
			sugm_js_goback();
		}elseif($return == SUGM_LOGIN_NAME_NOTFOUND){
			$errorfields['login_name'] = true;
			$errors['login_name_notfound'] = true;
		}elseif($return == SUGM_LOGIN_PASSWORD_INCORRECT){
			$errorfields['login_password'] = true;
			$errors['login_password_incorrect'] = true;
		}elseif($return == SUGM_LOGIN_NOTACTIVED){
			$errors['login_notactived'] = true;
		}elseif($return == SUGM_LOGIN_BANNED){
			$errors['login_banned'] = true;
		}else{
			$errors['login_unknow'] = true;
		}
	}
}

?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Login</title>
<meta name="description" content="sugm" />
<link rel="stylesheet" type="text/css" href="images/core.css">
<link rel="stylesheet" type="text/css" href="images/main-context.css">
<link rel="stylesheet" type="text/css" href="images/misc.css">
</head>

<body>
<div id="container">

<div id="header">

<h1>Login Panel</h1>
<ul>
<li><a href="<?php echo $GLOBALS['url_admin']?>">Admin Panel</a></li>
<li><a href="<?php echo $GLOBALS['url_password_change']?>">Change Password</a></li>
<li><a href="<?php echo $GLOBALS['url_logout']?>">Logout</a></li>
</ul>
</div>
<div id="maincontent">


<form action="<?php echo $GLOBALS['url_login']?>" method="post">
<div class="fieldRow">
<label>User Name</label>
<span><input type="text" name="user_name" id="user_pass" value="" style="width:150px;" maxlength="20" /></span></div>
<div class="fieldRow">
<label>Password</label>
<span><input type="password" name="user_pass" id="user_pass" value="" style="width:150px;" maxlength="20" /></span></div>
<div class="fieldRow">
<label></label>
<span><button type="submit" class="submit">Login</button><br />
<a href="<?php echo $GLOBALS['url_password_reset']?>">Forget Password?</a>
</span>
</div>
</form>
</div>
<div id="footer">
powered by <?php echo $Config['footmsg_tag']?>
</div>

</div>
</body>
</html>
